<?php
class Retailer_Backend_Helper_Observer extends Mage_Core_Helper_Abstract
{

/**

* Event Hook: checkout_type_onepage_save_order

* @param $observer Varien_Event_Observer

*/



public function hookToOrderSaveEvent( $observer)

{

/**

* NOTE:

* Order has already been saved, now we simply add some stuff to it,

* that will be saved to database. We add the stuff to Order object property

* called "inchoo_custom_info"

*/
//$orderextra = Mage::app()->getRequest()->getPost('order_type',false);
//if($orderextra!=null){
//$order = $observer->getEvent()->getOrder()->setOrderType($orderextra);
$order = new Mage_Sales_Model_Order();
//
//}
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
//
$order->loadByIncrementId($incrementId);
//if($order->getData('customer_id')!=null&&Mage::getModel('backend/backend')->load($order->getData('customer_id'),'customer_id')!=null){
//    $order->setData('order_type', "Wholesale");
//    $order->setData('order_type', $orderextra);
//}
//else{
//    $order->setData('order_type', "Retail");
//}
//$order->setOrderType($orderextra);
$id = $order->getStore()->getId();
$backend = Mage::getModel('backend/backend')->load($id,'store_id');
$currentComm = $backend->getCommission();
$subtot = $order->getSubtotal();

$items=$order->getItemsCollection();
      $wholesaletot=0.00;
      foreach($items as $item){
          $item = Mage::getModel('catalog/product')->load($item->getProductId());
          //$item->setStoreId(0);
          $wholesaletot=$wholesaletot+$item->getCost();
      }
$value=($subtot-$wholesaletot);

$backend->setCommission($currentComm+$value);
$backend->save();
//$order->save();



}
}
